import { defineStore } from 'pinia'
import { ref } from 'vue'
import { HomeService } from '@/apis'

export const useOverViewStore = defineStore(
    'over-view',
    () => {
        const most_played_albums = ref<album_info[]>([])
        const most_played_artists = ref<artist_info[]>([])
        const most_played_songs = ref<song_info[]>([])
        const recently_added_albums = ref<album_info[]>([])
        const recently_added_songs = ref<song_info[]>([])
        const recently_played_songs = ref<song_info[]>([])

        const setOverView = (newOverView : overview_result) => {
            most_played_albums.value = newOverView.most_played_albums
            most_played_artists.value = newOverView.most_played_artists
            most_played_songs.value = newOverView.most_played_songs
            recently_added_albums.value = newOverView.recently_added_albums
            recently_added_songs.value = newOverView.recently_added_songs
            recently_played_songs.value = newOverView.recently_played_songs
        }
        const initOverView = async () => {
            const res = await HomeService()
            setOverView(res.data as overview_result)
        }

        return {
            most_played_albums,
            most_played_artists,
            most_played_songs,
            recently_added_albums,
            recently_added_songs,
            recently_played_songs,
            setOverView,
            initOverView
        }
    },
    {
        persist: false
    }
)
